Public Class B1DbConnection
    Private SBOCompany As SAPbobsCOM.Company = B1Addon.B1Addon.SBOCompany
    Private SBOApp As SAPbouiCOM.Application = B1Addon.B1Addon.SBOApp

    Private _PassWord As String = ""
    Private _UserID As String
    Private _DataSource As String
    Private _ApplicationName As String
    Private _DbName As String
    Private _Provider As String

    Sub New()
        _DbName = SBOCompany.CompanyDB
        _UserID = SBOCompany.DbUserName
        _DataSource = SBOCompany.Server
        _ApplicationName = System.Windows.Forms.Application.ProductName
        _Provider = "SQLOLEDB.1"
    End Sub

    Public Property DBName() As String
        Get
            Return _DbName
        End Get
        Set(ByVal value As String)
            _DbName = value
        End Set
    End Property

    Public Property Provider() As String
        Get
            Return _Provider
        End Get
        Set(ByVal value As String)
            value = _Provider
        End Set
    End Property

    Public Property PassWord() As String
        Get
            Return _PassWord
        End Get
        Set(ByVal value As String)
            _PassWord = value
        End Set
    End Property

    Public Property UserID() As String
        Get
            Return _UserID
        End Get
        Set(ByVal value As String)
            _UserID = value
        End Set
    End Property

    Public Property ServerName() As String
        Get
            Return _DataSource
        End Get
        Set(ByVal value As String)
            _DataSource = value
        End Set
    End Property

    Public ReadOnly Property ApplicationName() As String
        Get
            Return _ApplicationName
        End Get
    End Property

    Public ReadOnly Property ConnectionString() As String
        Get
            Dim constr As String
            constr = "Provider=" & Me.Provider & ";"
            constr += "User ID=" & Me.UserID & ";"
            If Me.PassWord <> "" Then
                constr += "Password=" & Me.PassWord & ";"
            End If
            constr += "Initial Catalog=" & Me.DBName & ";"
            constr += "Data Source=" & Me.ServerName & ";"
            constr += "Persist Security Info=True;" '+ "Extended Properties=""Password ID=" & Me.PassWord & """;"
            constr += "Application Name=" & Me.ApplicationName
            Return constr
        End Get
    End Property

    'Public Function GetConnectionString() As String
    '    '"Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=LiYing-II;Data Source=DELL1;Application Name=ADDON"
    'End Function
End Class
